<h2>TEST of Migration</h2>
<?php
$hostname="localhost";
//$hostname1="127.0.0.1";
$username="root";
$password="";
$dbh1 = mysql_connect($hostname, $username, $password); 
$dbh2 = mysql_connect($hostname, $username, $password, true); 

mysql_select_db('madame_mdm_new', $dbh1);
mysql_select_db('gocartdbgocartdb_dump', $dbh2);
//Then to query database 1, do this:

$row_quey= mysql_query('Select id, product_name, product_code, product_price, product_special_price, product_short_descp, product_descp , product_weight, product_stock, page_title, meta_discription, status FROM madame_mdm_new.products', $dbh1);
//and for database 2:
  $table= "<table>";
  	$table .= '<tr><td>id</td><td>product_name</td><td>slug</td><td>product_price</td><td>product_special_price</td><td>product_short_descp</td><td>product_weight</td><td>page_title</td><td>meta_discription</td><td>status</td></tr>';
  
  
function randomPrefix($length) 
{ 
$random= "";
srand((double)microtime()*1000000);

$data = "ADE123IJKLMN67QRSTUVWXYZ"; 
$data .= "ZXYWVMNOPRSTUABCDEFG"; 
$data .= "0FGH45OP89";

for($i = 0; $i < $length; $i++) 
{ 
$random .= substr($data, (rand()%(strlen($data))), 1); 
}

return $random; 
}

while( $row= mysql_fetch_array($row_quey))
{
     //	 echo "<pre>";
	// print_r($row);	
	  $id = $row['id'];
	  $product_name = $row['product_name'];
	  $product_code = $row['product_code'];
	  $product_price = $row['product_price'];
      $product_special_price = $row['product_special_price'];
	  $product_short_descp = $row['product_short_descp'];
	  $product_weight = $row['product_weight'];
	  $page_title = $row['page_title'];
	  $meta_discription = $row['meta_discription'];
	  $status = $row['status'];
	//echo "<hr>";
	  
	  $slug = strtolower(str_replace(" ", "", "$product_name"));
	  $route_id="route_id";
	$table .= '<tr><td>'.$id.'</td><td>'.$product_name.'</td><td>'.$slug.'</td><td>'.$product_price.'</td><td>'.$product_special_price.'</td><td>'.$product_short_descp.'</td><td>'.$product_weight.'</td><td>'.$page_title.'</td><td>'.$meta_discription.'</td><td>'.$status.'</td></tr>';
	//echo  $id ."|".$product_name."";
	  $r_id= "cart/product/$id";
echo $check_route="Select * from gc_routes where route='".$r_id."'";
$row_quey_route = mysql_query($check_route, $dbh2);
   $num_rows= mysql_num_rows($row_quey_route);
 echo "<br>";
	if($num_rows==0)
	{
		echo  $sql_route = "INSERT INTO `gc_routes` (`id`, `slug`, `route`) VALUES (NULL, '$slug', 'cart/product/$id')";
		 $row_quey_process = mysql_query($sql_route, $dbh2);
		 $last_route_id =mysql_insert_id();
		//$last_route_id ="";
	}else
	{
	echo $id."Already present Route  ";
	}
	
	$check_products= "Select * from gc_products where id=$id";
    $row_quey_products = mysql_query($check_products, $dbh2);
    $num_rows_products= mysql_num_rows($row_quey_products);
	$sku = randomPrefix(6); 
	if($num_rows_products==0)
	{
	 echo  $sql1 = "INSERT INTO `gocartdbgocartdb_dump`.`gc_products`
	  (`id`, `sku`, `name`, `slug`, `route_id`, `description`, `excerpt`, `price`, `saleprice`, `free_shipping`, `shippable`, `taxable`, `fixed_quantity`, `weight`, `track_stock`, `quantity`, `related_products`, `images`, `seo_title`, `meta`, `enabled`) VALUES 
	  ($id, '$sku', '$product_name', '$slug', '$last_route_id', '$product_short_descp ', '$product_short_descp', '$product_price', '$product_special_price', '0', '1', '1', '0', '$product_weight', '0', '', NULL, 'false', NULL, NULL, '$status');";
	  echo "<br>";
	 $row_quey_category = mysql_query($sql1, $dbh2);
	}else
	{
	echo $id."Already present Product  ";
	}
	
}
    $table .= "</table>";

?>

